package com.eims.sls_app.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import bls.juejin.cn.R;

public class WebViewForPayActivity extends MyBaseActivity {
	public WebView webview;
	private WebSettings mWebSettings;
	boolean isfirst = false;
private String url;
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.webview_play);

		Log.e("we","webview");

		Bundle bundle=getIntent().getExtras();
		url=bundle.getString("url");

		// 加载页面
		webview = (WebView) findViewById(R.id.webview);
		webview.loadUrl(url);
		WebSettings webSettings = webview.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webSettings.setAllowFileAccess(true);
		webSettings.setBuiltInZoomControls(true);
		webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
		webSettings.setDomStorageEnabled(true);
		webSettings.setGeolocationEnabled(true);
		webview.setWebViewClient(new WebViewClient() {
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
			}
			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
			}
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				if (url.contains("alipays:")) {
					Intent intent;
					try {
						intent = Intent.parseUri(url,
								Intent.URI_INTENT_SCHEME);
						intent.addCategory(Intent.CATEGORY_BROWSABLE);
						intent.setComponent(null);
						startActivity(intent);

					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					webview.loadUrl(url);
				}
				return false;
			}
		});
	}


}
